package gin_http

import (
	"gitee.com/captials-team/ubdframe/src/domain/dto"
	"github.com/gin-gonic/gin"
	"net/http"
	"net/http/httptest"
)

// NewTestContext 测试用gin.context, 默认post请求，可自行修改
func NewTestContext() (*gin.Context, *httptest.ResponseRecorder) {
	//gin.SetMode(gin.ReleaseMode)

	w := httptest.NewRecorder()
	ctx, _ := gin.CreateTestContext(http.ResponseWriter(w))
	ctx.Request, _ = http.NewRequest("POST", "", nil)
	ctx.Request.Header.Set("Content-Type", "application/json; charset=utf-8")
	return ctx, w
}

// NewTestAuthContext 测试用gin.context
func NewTestAuthContext() (*gin.Context, *httptest.ResponseRecorder) {
	ctx, w := NewTestContext()

	SetAuth(ctx, &dto.AuthDataPacket{
		Auth: dto.AuthInfo{
			Id:       1,
			Nickname: "demo",
			Account:  "demo",
			Avatar:   "",
			Status:   1,
			SaasId:   0, Extends: map[string]string{
				"is_root": "0",
				"email":   "",
				"phone":   "1888",
			}},
	})
	return ctx, w
}
